import axios from '@/libs/api.request'

export const login = ({ userName, password, code }) => {
  const data = {
    'manage_phone': userName,
    'manage_pass': password,
    'code': code
  }

  return axios.request({
    url: 'login',
    data,
    method: 'post'
  })
}

export const getUserInfo = (token) => {
  return axios.request({
    url: 'get_info',
    method: 'get'
  })
}

export const getUserMenus = () => {
  return axios.request({
    url: 'get_user_menus',
    method: 'get'
  })
}

export const logout = (token) => {
  return axios.request({
    url: 'logout',
    method: 'get'
  })
}

export const addUserMember = ({ nickname, phone, email, pass, avator, state }) => {
  const data = { nickname, phone, email, pass, avator, state }
  return axios.request({
    url: 'add_user_member',
    data,
    method: 'post'
  })
}
export const getUserMember = ({ pageNum, pageSize }) => {
  return axios.request({
    url: 'get_user_member',
    params: {
      pageNum,
      pageSize
    },
    method: 'get'
  })
}

export const setMemberState = ({ member_id, setAction }) => {
  return axios.request({
    url: 'set_member_state',
    params: {
      member_id,
      setAction
    },
    method: 'get'
  })
}

export const delMemberUser = (member_id) => {
  return axios.request({
    url: 'del_member_user',
    params: {
      member_id
    },
    method: 'get'
  })
}

export const editMemberUser = ({ member_id, nickname, phone, email, pass, avator, state }) => {
  const data = {
    member_id,
    nickname,
    phone,
    email,
    pass,
    avator,
    state
  }
  return axios.request({
    url: 'edit_member_user',
    data,
    method: 'post'
  })
}

export const getMemberInfo = (member_id) => {
  return axios.request({
    url: 'get_member_info',
    params: {
      member_id
    },
    method: 'get'
  })
}
//= =
export const getUnreadCount = () => {
  return axios.request({
    url: 'message/count',
    method: 'get'
  })
}

export const getMessage = () => {
  return axios.request({
    url: 'message/init',
    method: 'get'
  })
}

export const getContentByMsgId = msg_id => {
  return axios.request({
    url: 'message/content',
    method: 'get',
    params: {
      msg_id
    }
  })
}

export const hasRead = msg_id => {
  return axios.request({
    url: 'message/has_read',
    method: 'post',
    data: {
      msg_id
    }
  })
}

export const removeReaded = msg_id => {
  return axios.request({
    url: 'message/remove_readed',
    method: 'post',
    data: {
      msg_id
    }
  })
}

export const restoreTrash = msg_id => {
  return axios.request({
    url: 'message/restore',
    method: 'post',
    data: {
      msg_id
    }
  })
}
